package com.TeacherInfoServer.mapper;

import com.TeacherInfoServer.pojo.DTO.SearchDTO.TeacherInfoChangeSearchDTO;
import com.TeacherInfoServer.pojo.entity.TeacherInfoChange;
import com.TeacherInfoServer.pojo.vo.TeacherInfoChangeListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TeacherInfoChangeMapper extends BaseMapper<TeacherInfoChange> {
    @Select("SELECT tc.*, ty.value as changeTypeValue, t.teacher_name as teacherName " +
            "FROM teacherinfo_change tc " +
            "LEFT JOIN type_info ty ON tc.change_type = ty.id " +
            "LEFT JOIN teacher t ON tc.teacher_id = t.teacher_id "
    )
    Page<TeacherInfoChangeListVo> getTeacherInfoChangeByPage(Page<?> page, @Param("qw") QueryWrapper<TeacherInfoChange> queryWrapper);

    @Select("SELECT tc.*, ty.value as changeTypeValue, t.teacher_name as teacherName " +
            "FROM teacherinfo_change tc " +
            "LEFT JOIN type_info ty ON tc.change_type = ty.id " +
            "LEFT JOIN teacher t ON tc.teacher_id = t.teacher_id "
    )
    List<TeacherInfoChangeListVo> getTeacherInfoChangeList();

    @Select("<script>" +
            "SELECT tc.*, ty.value as changeTypeValue, t.teacher_name as teacherName " +
            "FROM teacherinfo_change tc " +
            "LEFT JOIN type_info ty ON tc.change_type = ty.id " +
            "LEFT JOIN teacher t ON tc.teacher_id = t.teacher_id " +
            "<where> " +
            "<if test='search.teacherId != null and search.teacherId.trim() != \"\"'> " +
            "AND tc.teacher_id LIKE CONCAT('%', #{search.teacherId}, '%') " +
            "</if> " +
            "<if test='search.teacherName != null and search.teacherName.trim() != \"\"'> " +
            "AND t.teacher_name LIKE CONCAT('%', #{search.teacherName}, '%') " +
            "</if> " +
            "<if test='search.changeTypeValue != null and search.changeTypeValue.trim() != \"\"'> " +
            "AND ty.value LIKE CONCAT('%', #{search.changeTypeValue}, '%') " +
            "</if> " +
            "<if test='search.changeDate != null and search.changeDate.trim() != \"\"'> " +
            "AND tc.change_date LIKE CONCAT('%', #{search.changeDate}, '%') " +
            "</if> " +
            "<if test='search.changeReason != null and search.changeReason.trim() != \"\"'> " +
            "AND tc.change_reason LIKE CONCAT('%', #{search.changeReason}, '%') " +
            "</if> " +
            "</where>" +
            "ORDER BY tc.change_date DESC" + // or any other order you want
            "</script>")
    Page<TeacherInfoChangeListVo> searchTeacherInfoChangeList(Page<?> page, @Param("search") TeacherInfoChangeSearchDTO search);

}
